package cn.yunhe.controller;

import cn.yunhe.entity.Stock;
import cn.yunhe.service.IStockService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 邓永凯 库存列表servlet
 */
@WebServlet("/after/StockListServlet")
public class StockListServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //调用service层的方法
        IStockService stockService = new IStockService();
        List<Stock> stockList = stockService.getAllStock();
        //保存到request域里面
        request.setAttribute("stockList",stockList);
        request.setAttribute("totalNum",stockList.size());
        //转发
        request.getRequestDispatcher("/after/stock-show.jsp").forward(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
